package com.github.chirspan.xaas.soa.message.factory;


import cn.hutool.core.util.StrUtil;
import com.github.chirspan.xaas.soa.message.core.SOAConstants;
import com.github.chirspan.xaas.soa.message.handler.DateValueHandler;
import com.github.chirspan.xaas.soa.message.handler.DefaultValueHandler;
import com.github.chirspan.xaas.soa.message.handler.IValueHandler;
import com.github.chirspan.xaas.soa.message.handler.StringValueHandler;

public class ValueHandlerFactory {

    public static IValueHandler getValueHandler(String type) {
        if (StrUtil.isNotBlank(type)) {
            type = type.trim();
            if (isDateOrTimeType(type)) {
                return new DateValueHandler();
            }
            if (SOAConstants.DATA_TYPE_STRING.equalsIgnoreCase(type)) {
                return new StringValueHandler();
            }
        }
        return new DefaultValueHandler();
    }

    private static boolean isDateOrTimeType(String type) {
        return SOAConstants.DATA_TYPE_DATE.equalsIgnoreCase(type)
                || SOAConstants.DATA_TYPE_TIME.equalsIgnoreCase(type)
                || SOAConstants.DATA_TYPE_TIMESTAMP.equalsIgnoreCase(type);
    }

}
